<?php
namespace app\logic;

use app\common\corelib\CacheHelper;
use app\models\Area;
use app\models\Goods;
use app\models\Play;
use app\models\Shop;
use app\models\ShopPlay;
use app\models\Stock;
use app\models\Tag;
use yii\db\Query;



class PlayGoodsLogic
{
    public function getPlayList($shop_id)
    {
        if($shop_id){
            $shopplay = ShopPlay::find()->where(['shop_id'=>$shop_id])->asArray()->all();
            $playids = array_column($shopplay,'play_id');
            $cardids = Play::find()->where(['type'=>1])->asArray()->all();
            $cardids = array_column($cardids,'play_id');
            $playids = array_unique(array_merge($playids,$cardids));
            return Play::find()->where(['status'=>1])->andWhere(['in','play_id',$playids])->asArray()->all();
        }else{
            return Play::find()->where(['status'=>1])->asArray()->all();
        }

    }

    public function getGoodsList(){
        return Goods::find()->where(['status'=>1])->asArray()->all();
    }

    public function getGoodsStock($region_code){
        if(strlen($region_code)==6){
            return Stock::find()->where(['district_id'=>$region_code])->asArray()->all();
        }else{
            return Stock::find()->where(['street_id'=>$region_code])->asArray()->all();
        }

    }

    public function getGoods($goods_id){
        return Goods::findOne(['goods_id'=>$goods_id])->toArray();
    }

    public function getGoodss($goods_id){
        return Goods::findOne(['goods_id'=>$goods_id,'status'=>1])->toArray();
    }

    public function getPlay($play_id){
        return Play::findOne(['play_id'=>$play_id])->toArray();
    }




}